<?php

namespace common\dao\dd;

/**
 * 字典数据
 *
 * @author peng.huang
 */
class DataDao extends DdDao {

    /**
     * 表名
     * 
     * @var string 
     */
    public $table = 'dd_data';

    /**
     * 返回注册用户类型
     *
     * @param bool $isFlip [是否键与值交换]
     * @param string|int $code [代码]  	
     * @return mixed
     */
    public function getRegisteredUserType($isFlip = TRUE, $code = NULL) {
        $func = function () {
            $data = $this->findAll('code,name', array('dd_type_code' => '00003'));
            $text = '';
            foreach ($data as $value) {
                $text .= sprintf('\'%s\'=>\'%s\',', $value ['code'], $value ['name']) . PHP_EOL;
            }

            unset($data);
            return $text;
        };

        return $this->_getDD('registered_usertype', $func, $isFlip, $code);
    }

    /**
     * 返回注册类型
     * 
     * @param bool $isFlip [是否键与值交换]
     * @param string|int $code [代码]
     * @return mixed
     */
    public function getRegisteredType($isFlip = TRUE, $code = NULL) {
        $func = function () {
            $data = $this->findAll('code,name', array('dd_type_code' => '00002'));
            $text = '';
            foreach ($data as $value) {
                $text .= sprintf('\'%s\'=>\'%s\',', $value ['code'], $value ['name']) . PHP_EOL;
            }

            unset($data);
            return $text;
        };

        return $this->_getDD('registered_type', $func, $isFlip, $code);
    }

}
